#include <stdio.h>


int minPathSum(int** grid, int gridSize, int* gridColSize)
{
    int m = gridSize;
    int n = *gridColSize;
    int result[m][n];
    result[0][0] = grid[0][0];
    for(int i = 1;i < m;i++)
    {
        result[i][0] = result[i-1][0] + grid[i][0];
        printf("%d\n",result[i][0]);
    }
    for(int j = 1;j < n;j++)
    {
        result[0][j] = result[0][j - 1] + grid[0][j];
    }
    for(int i = 1;i < m;i++)
    {
        for(int j = 1;j < n;j++)
        {
            result[i][j] = (result[i-1][j] + grid[i][j]) < (result[i][j-1] + grid[i][j]) ? 
                            (result[i-1][j] + grid[i][j]) : (result[i][j-1] + grid[i][j]);
        }
    }
    return result[m-1][n-1];
}

int main()
{
    int *grid[3];
    int nums1[] = {1,3,1};
    int nums2[] = {1,5,1};
    int nums3[] = {4,2,1};
    grid[0] = nums1;
    grid[1] = nums2;
    grid[2] = nums3;
    int col = sizeof(nums1) / sizeof(nums1[0]);

    int m = minPathSum(grid,3,&col);
    printf("m = %d\n",m);

    return 0;
}